package com.polaris.live.adapter.vip

import androidx.constraintlayout.widget.ConstraintLayout
import com.bumptech.glide.Glide
import com.polaris.live.common.adapter.BaseBindingAdapter
import com.polaris.live.common.adapter.VBViewHolder
import com.polaris.live.common.constant.CommonConst
import com.polaris.live.common.ext.autoDp
import com.polaris.live.databinding.ItemVipIdentityBinding
import com.polaris.live.resp.back_resp.UserVipIdentity
import com.polaris.live.utils.VipStyle
import com.polaris.live.utils.image.ImageUtils

/**
 * VipIdentityAdapter  vip专属身份
 *
 * @author Created by 天晴 on 2024/12/10/031 11:44
 */
class VipIdentityAdapter(
    private val mLevel: Long,
) : BaseBindingAdapter<ItemVipIdentityBinding, UserVipIdentity>() {

    override fun convert(
        holder: VBViewHolder<ItemVipIdentityBinding>,
        item: UserVipIdentity,
    ) {
        holder.vb.apply {
            bgImg.setImageResource(VipStyle.getVipStyle(mLevel).vipBoxBg)
            if (item.explain == "-1") { //为占位数据
                return
            }
            val lp = itemImg.layoutParams as ConstraintLayout.LayoutParams
            when (item.decorationType) {
                CommonConst.DressUp.AVATAR_FRAME -> { //头像框
                    if ((item.width ?: 0) > 0 && (item.height ?: 0) > 0) {
                        lp.width = item.width?.autoDp ?: 64.autoDp
                        lp.height = item.height?.autoDp ?: 64.autoDp
                    } else {
                        lp.width = 64.autoDp
                        lp.height = 64.autoDp
                    }
                    itemImg.layoutParams = lp
                }

                CommonConst.DressUp.CHAT_BUBBLE -> {//聊天气泡
                    if ((item.width ?: 0) > 0 && (item.height ?: 0) > 0) {
                        lp.width = item.width?.autoDp ?: 50.autoDp
                        lp.height = item.height?.autoDp ?: 45.autoDp
                    } else {
                        lp.width = 50.autoDp
                        lp.height = 45.autoDp
                    }
                    itemImg.layoutParams = lp

                }

                CommonConst.DressUp.USER_PROFILE -> {//用户资料卡片
                    if ((item.width ?: 0) > 0 && (item.height ?: 0) > 0) {
                        lp.width = item.width?.autoDp ?: 96.autoDp
                        lp.height = item.height?.autoDp ?: 42.autoDp
                    } else {
                        lp.width = 96.autoDp
                        lp.height = 42.autoDp
                    }
                    itemImg.layoutParams = lp

                }

                CommonConst.DressUp.LIVE_BROADCAST_ENTRY -> {//直播进场座驾
                    if ((item.width ?: 0) > 0 && (item.height ?: 0) > 0) {
                        lp.width = item.width?.autoDp ?: 72.autoDp
                        lp.height = item.height?.autoDp ?: 72.autoDp
                    } else {
                        lp.width = 72.autoDp
                        lp.height = 72.autoDp
                    }
                    itemImg.layoutParams = lp

                }

                CommonConst.DressUp.LIVE_EFFECT -> { //直播进场特效
                    if ((item.width ?: 0) > 0 && (item.height ?: 0) > 0) {
                        lp.width = item.width?.autoDp ?: 94.autoDp
                        lp.height = item.height?.autoDp ?: 24.autoDp
                    } else {
                        lp.width = 94.autoDp
                        lp.height = 24.autoDp
                    }
                    itemImg.layoutParams = lp

                }

                CommonConst.DressUp.HOMEPAGE_BACKGROUND -> {//个人主页背景
                    if ((item.width ?: 0) > 0 && (item.height ?: 0) > 0) {
                        lp.width = item.width?.autoDp ?: 90.autoDp
                        lp.height = item.height?.autoDp ?: 40.autoDp
                    } else {
                        lp.width = 90.autoDp
                        lp.height = 40.autoDp
                    }
                    itemImg.layoutParams = lp
                }

                CommonConst.DressUp.PARTY_BACKGROUND -> {//派对背景
                    if ((item.width ?: 0) > 0 && (item.height ?: 0) > 0) {
                        lp.width = item.width?.autoDp ?: 31.autoDp
                        lp.height = item.height?.autoDp ?: 66.autoDp
                    } else {
                        lp.width = 31.autoDp
                        lp.height = 66.autoDp
                    }
                    itemImg.layoutParams = lp

                }

                else -> {
                    if ((item.width ?: 0) > 0 && (item.height ?: 0) > 0) {
                        lp.width = item.width?.autoDp ?: 80.autoDp
                        lp.height = item.height?.autoDp ?: 80.autoDp
                    } else {
                        lp.width = 80.autoDp
                        lp.height = 80.autoDp
                    }
                    itemImg.layoutParams = lp
                }
            }

            Glide.with(context)
                .load(ImageUtils.imgPath(item.icon))
                .into(itemImg)
            nameTv.text = item.name
        }
    }

}